/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 小球组件
 * @Description *
 * @Package concurrent.runningball
 * @date 2021/4/1 3:56 下午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package concurrent.runningball;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class BallComponent extends JPanel {

    private ArrayList<Ball> balls = new ArrayList<>();

    public void add(Ball b) {
        balls.add(b);
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        for (Ball b : balls) {
            g2.fill(b.getShape());
        }
    }

}
